Paralelipiped.prototype = new Shape3D();  
Paralelipiped.prototype.constructor=Paralelipiped;
function Paralelipiped(position, points, colors){
	this.position = position;
	this.points = points;
	this.vertices = new Array();
	this.vertexSize = 3;
	
	this.colors = colors?colors:null;
	this.verticeColors = null;
	this.colorSize = 4;
	this.animations = new Array();
	
	this.initVertices = function(){
		//debugger;
		if(this.points.length!=8) throw "We need 8 points for defining a paralelipiped.";
		
		// this is base face 1
		// try with 2 faces
		if(false){
			var faces = 2;
			this.vertexSize = 4;
			var v1 = this.points[0];
			var v2 = this.points[1];
			var v3 = this.points[2];
			var v4 = this.points[3];
			
			// this is base face 2
			var w1 = this.points[0];
			var w2 = this.points[1];
			var w3 = this.points[2];
			var w4 = this.points[3];
			
			// create base face 1
			this.vertices.push(v1.x);this.vertices.push(v1.y);this.vertices.push(v1.z);
			this.vertices.push(v2.x);this.vertices.push(v2.y);this.vertices.push(v2.z);
			this.vertices.push(v3.x);this.vertices.push(v3.y);this.vertices.push(v3.z);
			this.vertices.push(v4.x);this.vertices.push(v4.y);this.vertices.push(v4.z);
			
			// create base face 2
			this.vertices.push(w1.x);this.vertices.push(w1.y);this.vertices.push(w1.z);
			this.vertices.push(w2.x);this.vertices.push(w2.y);this.vertices.push(w2.z);
			this.vertices.push(w3.x);this.vertices.push(w3.y);this.vertices.push(w3.z);
			this.vertices.push(w4.x);this.vertices.push(w4.y);this.vertices.push(w4.z);	
		}		
		else{
			var faces = 0;
			var v1 = this.points[0];
			var v2 = this.points[1];
			var v3 = this.points[2];
			var v4 = this.points[3];
			
			// this is base face 2
			var w1 = this.points[4];
			var w2 = this.points[5];
			var w3 = this.points[6];
			var w4 = this.points[7];
			
			// create base face 1
			this.vertices.push(v1.x);this.vertices.push(v1.y);this.vertices.push(v1.z);
			this.vertices.push(v2.x);this.vertices.push(v2.y);this.vertices.push(v2.z);
			this.vertices.push(v3.x);this.vertices.push(v3.y);this.vertices.push(v3.z);
			
			this.vertices.push(v2.x);this.vertices.push(v1.y);this.vertices.push(v2.z);
			this.vertices.push(v3.x);this.vertices.push(v3.y);this.vertices.push(v3.z);
			this.vertices.push(v4.x);this.vertices.push(v4.y);this.vertices.push(v4.z);
			faces+=2
			
			// create base face 2
			this.vertices.push(w1.x);this.vertices.push(w1.y);this.vertices.push(w1.z);
			this.vertices.push(w2.x);this.vertices.push(w2.y);this.vertices.push(w2.z);
			this.vertices.push(w3.x);this.vertices.push(w3.y);this.vertices.push(w3.z);
			
			this.vertices.push(w2.x);this.vertices.push(w1.y);this.vertices.push(w2.z);
			this.vertices.push(w3.x);this.vertices.push(w3.y);this.vertices.push(w3.z);
			this.vertices.push(w4.x);this.vertices.push(w4.y);this.vertices.push(w4.z);	
			faces+=2
			
			// create inter face 1
			this.vertices.push(v1.x);this.vertices.push(v1.y);this.vertices.push(v1.z);
			this.vertices.push(v2.x);this.vertices.push(v2.y);this.vertices.push(v2.z);
			this.vertices.push(w1.x);this.vertices.push(w1.y);this.vertices.push(w1.z);
			
			this.vertices.push(w1.x);this.vertices.push(w1.y);this.vertices.push(w1.z);
			this.vertices.push(w2.x);this.vertices.push(w2.y);this.vertices.push(w2.z);
			this.vertices.push(v2.x);this.vertices.push(v2.y);this.vertices.push(v2.z);
			faces+=2
			
			// create inter face 2
			this.vertices.push(v2.x);this.vertices.push(v2.y);this.vertices.push(v2.z);
			this.vertices.push(v3.x);this.vertices.push(v3.y);this.vertices.push(v3.z);
			this.vertices.push(w2.x);this.vertices.push(w2.y);this.vertices.push(w2.z);
			
			this.vertices.push(w2.x);this.vertices.push(w1.y);this.vertices.push(w2.z);
			this.vertices.push(w3.x);this.vertices.push(w2.y);this.vertices.push(w3.z);
			this.vertices.push(v3.x);this.vertices.push(v3.y);this.vertices.push(v3.z);
			faces+=2
			
			// create inter face 3
			this.vertices.push(v3.x);this.vertices.push(v3.y);this.vertices.push(v3.z);
			this.vertices.push(v4.x);this.vertices.push(v4.y);this.vertices.push(v4.z);
			this.vertices.push(w3.x);this.vertices.push(w3.y);this.vertices.push(w3.z);
			
			this.vertices.push(w3.x);this.vertices.push(w3.y);this.vertices.push(w3.z);
			this.vertices.push(w4.x);this.vertices.push(w4.y);this.vertices.push(w4.z);
			this.vertices.push(v4.x);this.vertices.push(v4.y);this.vertices.push(v4.z);
			faces+=2
			
			// create inter face 3
			this.vertices.push(v4.x);this.vertices.push(v4.y);this.vertices.push(v4.z);
			this.vertices.push(v1.x);this.vertices.push(v1.y);this.vertices.push(v1.z);
			this.vertices.push(w1.x);this.vertices.push(w1.y);this.vertices.push(w1.z);
			
			this.vertices.push(w4.x);this.vertices.push(w4.y);this.vertices.push(w4.z);
			this.vertices.push(w1.x);this.vertices.push(w1.y);this.vertices.push(w1.z);
			this.vertices.push(v4.x);this.vertices.push(v4.y);this.vertices.push(v4.z);
			faces+=2
		}
		
		// construct colors
		if(colors){
			if(this.colors.length!=4) throw "We need 4 color points for defining a paralelipiped color.";
			this.verticeColors = new Array();
			var c1=this.colors[0];
			var c2=this.colors[1];
			var c3=this.colors[2];
			var c4=this.colors[3];
			for(var i=0;i<faces;i++){
				this.verticeColors.push(c1.r);this.verticeColors.push(c1.g);this.verticeColors.push(c1.b);this.verticeColors.push(c1.a);
				this.verticeColors.push(c2.r);this.verticeColors.push(c2.g);this.verticeColors.push(c2.b);this.verticeColors.push(c2.a);
				this.verticeColors.push(c3.r);this.verticeColors.push(c3.g);this.verticeColors.push(c3.b);this.verticeColors.push(c3.a);
				this.verticeColors.push(c4.r);this.verticeColors.push(c4.g);this.verticeColors.push(c4.b);this.verticeColors.push(c4.a);
			}
		}
	}
}